package com.thinkersre.util;

public class RedisKeyUtil{
    private static final String SPLIT = ":";
    public static final String PREFIX_ENTITY_LIKE = "like:entity";
    private static final String PREFIX_USER_LIKE = "like:user";
    private static final String PREFIX_FOLLOWEE = "followee";
    private static final String PREFIX_FOLLOWER = "follower";
    private static final String PREFIX_KAPTCHA = "kaptcha";
    private static final String PREFIX_TICKET = "ticket";

    private static final String PREFIX_USER = "user";
    //访问量
    // UV (网站访问用户数量---根据Ip地址统计(包括没有登录的用户))
    private static final String PREFIX_UV = "uv";
    //日活跃用户
    // DAU (活跃用户数量---根据userId)
    private static final String PREFIX_DAU = "dau";
    private static final String PREFIX_POST = "post";
    //某个实体的赞
    //like:entity:entityType:entityId => set(userId)
    public static String getEntityLikeKey(int entityType, int entityId){
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }


    //某用户的赞
    //like:user:userId => int
    public static String getUserLikeKey(int userId){
        return PREFIX_USER_LIKE + SPLIT + userId;
    }

    //某个用户关注的实体
    //followee:userId:entityType => zset(entityId,now)//主体关注的是关注者，所以userId在前面
    public static String getFolloweeKey(int userId,int entityType){

        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

    //某个用户拥有的粉丝
    //follower:entityType:userId => zset(userId,now)//主题关注的是被关注者，被关注者是对象，所以在前面
    public static String getFollowerKey(int entityType, int entityId){
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }


    //登录验证码
    public static String getKaptchaKey(String owner){
        return PREFIX_KAPTCHA + SPLIT + owner;
    }

    // 登录凭证
    public static String getTicketKey(String ticket){
        return PREFIX_TICKET + SPLIT + ticket;
    }

    public static String getUserKey(int userId) {
        return PREFIX_USER + SPLIT + userId;
    }

    //单日UV
    /**
     * 存储单日ip访问数量（uv）--HyperLogLog ---k:时间 v:ip  (HyperLogLog)
     * 示例：uv:20220526 = ip1,ip2,ip3,...
     */
    public static String getUVKey(String date){
        return PREFIX_UV+SPLIT+date;
    }
    //区间UV
    /**
     * 获取区间ip访问数量（uv）
     * 示例：uv:20220525:20220526 = ip1,ip2,ip3,...
     */
    public static String getUVKey (String startDate,String endDate){
        return PREFIX_UV+SPLIT+startDate+SPLIT+endDate;

    }
    //单日活跃用户
    /**
     * 存储单日活跃用户（dau）--BitMap ---k:date v:userId索引下为true  (BitMap)
     * 示例：dau:20220526 = userId1索引--(true),userId2索引--(true),....
     */
    public static String getDAUKey(String date){
        return PREFIX_DAU+SPLIT+date;
    }
    //区间活跃用户
    /**
     * 获取区间活跃用户
     * 示例：dau:20220526:20220526
     */
    public static String getDAUKey(String startDate,String endDate){
        return PREFIX_DAU+SPLIT+startDate+SPLIT+endDate;
    }

    //帖子分数
    public static String getPostScoreKey(){
        return PREFIX_POST + SPLIT + "score";
    }


}
